package org.nyt.medicalstore.controller;

import org.nyt.medicalstore.model.Drug;
import org.nyt.medicalstore.service.RecommendationService;
import org.nyt.medicalstore.service.ConsultationService;
import org.nyt.medicalstore.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/intelligent")
public class IntelligentController {
    @Autowired
    private RecommendationService recommendationService;

    @Autowired
    private ConsultationService consultationService;

    @Autowired
    private CustomerService customerService;

    // 智能推荐相关接口
    @GetMapping("/recommend/symptoms")
    public List<Drug> recommendBySymptoms(@RequestParam String symptoms) {
        return recommendationService.recommendBySymptoms(symptoms);
    }

    @GetMapping("/recommend/related/{drugId}")
    public List<Drug> recommendRelatedDrugs(@PathVariable Long drugId) {
        return recommendationService.recommendRelatedDrugs(drugId);
    }

    @GetMapping("/recommend/user/{userId}")
    public List<Drug> recommendByUserHistory(@PathVariable Long userId) {
        return recommendationService.recommendByUserHistory(userId);
    }

    @GetMapping("/recommend/popular")
    public List<Drug> getPopularRecommendations() {
        return recommendationService.getPopularRecommendations();
    }

    // 智能咨询相关接口
    @PostMapping("/consult")
    public Map<String, Object> consult(@RequestParam String query) {
        return consultationService.consult(query);
    }

    @GetMapping("/consult/faqs")
    public List<Map<String, String>> getFAQs() {
        return consultationService.getFAQs();
    }

    @GetMapping("/consult/drug/{drugId}/instructions")
    public Map<String, String> getDrugInstructions(@PathVariable Long drugId) {
        return consultationService.getDrugInstructions(drugId);
    }

    // 智能客服相关接口
    @PostMapping("/customer/query")
    public Map<String, Object> handleCustomerQuery(
            @RequestParam String query,
            @RequestParam Long customerId) {
        return customerService.handleCustomerQuery(query, customerId);
    }

    @GetMapping("/customer/{customerId}/orders")
    public List<Map<String, Object>> getCustomerOrderHistory(@PathVariable Long customerId) {
        return customerService.getCustomerOrderHistory(customerId);
    }

    @PostMapping("/customer/order/{orderId}/issue")
    public Map<String, Object> handleOrderIssue(
            @RequestParam String issue,
            @PathVariable Long orderId) {
        return customerService.handleOrderIssue(issue, orderId);
    }

    @GetMapping("/customer/{customerId}")
    public Map<String, Object> getCustomerInfo(@PathVariable Long customerId) {
        return Map.of(
                "customer", customerService.getCustomerInfo(customerId)
        );
    }
} 